/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.service;

import br.com.foxline.model.City;
import br.com.foxline.model.Country;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author ely
 */
@Stateless
public class CountryService extends GenericService<Country> {

    public CountryService() {
        super(Country.class);
    }

    public List<Country> autocomplete(String str) {
        List<Country> lista = new ArrayList<Country>();
        String sql = "Select c from Country c where"; 
        
        if (str != null) {
            sql +=" lower(c.name) like lower(:name)";
        }
        
        Query query = getEntityManager().createQuery(sql).setMaxResults(50);

        if (str != null) {
            query.setParameter("name", "" + str + "%");
        }

        lista = query.getResultList();
        return lista;

    }
}
